﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OConf.API.Filter;
using OConf.IBLL;
using OConf.Model.Common;
using OConf.Model.RequestInput.ConfigInfo;
using OConf.Model.RequestInput.ProjectInfo;

namespace OConf.API.Controllers
{
    [Authorize]
    [Route("api/[Controller]/[Action]")]
    [ApiController]
    public class ProjectInfoController : ControllerBase
    {
        private readonly IProjectInfoBLL _projectInfoBLL;
     
        public ProjectInfoController(IProjectInfoBLL projectInfoBLL)
        {
            _projectInfoBLL = projectInfoBLL;
           
        }

        /// <summary>
        /// 新增项目信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ReturnData<bool> AddProjectInfo([FromBody] AddProjectInfoInput input)
        {
            return _projectInfoBLL.AddProjectInfo(input);
        }

        /// <summary>
        /// 编辑项目信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ReturnData<bool> EditProjectInfo([FromBody] EditProjectInfoInput input)
        {
            return _projectInfoBLL.EditProjectInfo(input);
        }

        /// <summary>
        /// 软删除项目信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ReturnData<bool> DeleteProjectInfo([FromBody] DeleteProjectInfoInput input)
        {
            return _projectInfoBLL.DeleteProjectInfo(input);
        }

        /// <summary>
        /// 系统管理员回收站删除项目信息（硬删除）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [PermissionForApi(AllowRole = Entity.RoleTypeEnum.系统管理员)]
        public ReturnData<bool> SysDelete([FromBody] DeleteProjectInfoInput input)
        {
            return _projectInfoBLL.SysDelete(input);
        }

        /// <summary>
        /// 还原项目信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [PermissionForApi(AllowRole = Entity.RoleTypeEnum.系统管理员)]
        public ReturnData<bool> Reduction([FromBody] DeleteProjectInfoInput input)
        {
            return _projectInfoBLL.Reduction(input);
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="queryParam"></param>
        /// <returns></returns>
        [HttpGet]
        public ReturnData<ReturnTableData<ProjectInfoModel>> QueryPage([FromQuery] QueryProjectInput queryParam)
        {
            return _projectInfoBLL.QueryPage(queryParam);
        }

        /// <summary>
        /// 回收站项目信息列表
        /// </summary>
        /// <param name="queryParam"></param>
        /// <returns></returns>
        [HttpGet]
        [PermissionForApi(AllowRole = Entity.RoleTypeEnum.系统管理员)]
        public ReturnData<ReturnTableData<ProjectInfoModel>> QueryRecycleProjectInfo([FromQuery] QueryProjectInput queryParam)
        {
            return _projectInfoBLL.QueryRecycleProjectInfo(queryParam);
        }

        /// <summary>
        /// 项目详情-包含的配置信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ReturnData<ProjectConfigs> GetProjectConfigs([FromQuery] GetProjectConfigsInput input)
        {
            return _projectInfoBLL.GetProjectConfigs(input);
        }

        /// <summary>
        /// 重置秘钥
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ReturnData<bool> ResetSecretKey([FromBody] ResetSecretKeyInput input)
        {
            return _projectInfoBLL.ResetSecretKey(input);
        }

        /// <summary>
        /// 一键生成配置文件信息 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ReturnData<bool> GenerateConfigFileInfo([FromBody] GenerateConfigInfoListInput input)
        {
            return _projectInfoBLL.GenerateConfigFileInfo(input);
        }
    }
}